#pragma once

#include "dispatcher.hpp"
#include "endpoint.hpp"
#include <thread>
#include <queue>
#include <mutex>

class TcpClient
{
public:
    TcpClient(Dispatcher& d) : dispatcher(d) {}
    ~TcpClient() { sock.Close(); cmdWorker.join(); }
    void Start(const EndPoint& peer);
private:
    void StartCmdLine(const Socket& sock);
    void ConnEstabilished(const Socket& sock);
    void HandleMessage(const Socket& sock);

    Dispatcher& dispatcher;
    Socket sock;
    std::mutex mtx;
    std::thread cmdWorker;
};